// // 1.引入http模块
const http = require('http');
const fs = require('fs');

const server = http.createServer((req, res) => {
  // 获取请求url的路径
  let { pathname } = new URL(req.url, 'http://127.0.0.1');
  if (pathname === '/') {
    let html = fs.readFileSync(__dirname + '/table.html');
    res.end(html)
  } else if (pathname === '/index.css') {
    let css = fs.readFileSync(__dirname + '/index.css');
    res.end(css)
  } else if (pathname === '/index.js') {
    let js = fs.readFileSync(__dirname + '/index.js');
    res.end(js)
  } else {
    res.statusCode = 404;
    res.end('404');

  }
});

server.listen(9000, () => {
  console.log('服务器启动成功');
});